package cn.edu.neusoft.neufooddemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.neufooddemo.R;
import cn.edu.neusoft.neufooddemo.activity.FoodListActivity;
import cn.edu.neusoft.neufooddemo.bean.Shop;
import cn.edu.neusoft.neufooddemo.common.Constants;

/**
 * Created by Shinelon on 2017/3/6.
 */

public class ShopAdapter extends RecyclerViewAdapter<ShopAdapter.ViewHolder> {

    public ShopAdapter(Context context, List data, int layoutResource) {
        super(context, data, layoutResource);
    }


    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        final Shop entity = (Shop) data.get(position);
        viewHolder.shop_title.setText(entity.getShopname());
        viewHolder.shop_address.setText(entity.getAddress());
        viewHolder.shop_rating.setRating(Float.valueOf(entity.getLevel()));
        Picasso.get().load(Constants.BASE_URL+entity.getPic()).into(viewHolder.shop_thumb);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, FoodListActivity.class);
                String id=entity.getShop_id();
                String shopname=entity.getShopname();
                intent.putExtra("id", id);
                intent.putExtra("shopname", shopname);
                intent.putExtra("phonenum", entity.getPhonenum());
                context.startActivity(intent);
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView shop_thumb;
        TextView shop_title,shop_address;
        RatingBar shop_rating;

        public ViewHolder(View itemView) {
            super(itemView);
            shop_title = (TextView) itemView.findViewById(R.id.shop_title);
            shop_thumb = (ImageView) itemView.findViewById(R.id.shop_thumb);
            shop_address = (TextView) itemView.findViewById(R.id.shop_address);
            shop_rating = (RatingBar) itemView.findViewById(R.id.shop_rating);

        }
    }
}

